// Copyright 2012 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dfa.axis.v1_17;

import com.google.api.ads.dfa.lib.client.DfaSession;
import com.google.api.ads.dfa.lib.factory.DfaServices;
import com.google.api.ads.dfa.axis.v1_17.Advertiser;
import com.google.api.ads.dfa.axis.v1_17.AdvertiserRecordSet;
import com.google.api.ads.dfa.axis.v1_17.AdvertiserRemote;
import com.google.api.ads.dfa.axis.v1_17.AdvertiserSearchCriteria;

/**
 * This example displays advertiser name, ID and spotlight configuration ID for
 * the given search criteria. Results are limited to first 10 records.
 *
 * Credentials and properties in {@code fromFile()} are pulled from the
 * "ads.properties" file. See README for more info.
 *
 * Tags: advertiser.getAdvertisers
 *
 * @author Joseph DiLallo
 */
public class GetAdvertisers {

  public static void main(String[] args) throws Exception {
    String searchString = "INSERT_SEARCH_STRING_CRITERIA_HERE";

    // Initialize your session.
    DfaSession session = new DfaSession.Builder().fromFile().build();

    // Request the advertiser service from the service client factory.
    AdvertiserRemote advertiserService = new DfaServices().get(session, AdvertiserRemote.class);

    // Create advertiser search criteria structure.
    AdvertiserSearchCriteria advSearchCriteria = new AdvertiserSearchCriteria();
    advSearchCriteria.setPageSize(10);
    advSearchCriteria.setSearchString(searchString);

    // Get advertiser record set.
    AdvertiserRecordSet advertiserRecordSet = advertiserService.getAdvertisers(
        advSearchCriteria);

    // Display advertiser names, IDs and spotlight configuration IDs.
    if (advertiserRecordSet.getRecords().length > 0) {
      for (Advertiser result : advertiserRecordSet.getRecords()) {
        System.out.printf("Advertiser with name \"%s\" , ID \"%s\" , and spotlight configuration "
            + "ID \"%s\" was found.%n", result.getName(), result.getId(), result.getSpotId());
      }
    } else {
      System.out.println("No advertisers found for your criteria.");
    }
  }
}
